package com.shqcjd.generalplatformprojectclient.api;

import com.lzy.okgo.OkGo;
import com.lzy.okrx2.adapter.ObservableBody;
import com.shqcjd.generalplatformprojectclient.helper.JsonConvert;
import com.shqcjd.generalplatformprojectclient.model.ResponseData;
import com.shqcjd.generalplatformprojectclient.model.pojo.CompanyBean;
import com.shqcjd.generalplatformprojectclient.model.pojo.DraftBean;
import com.shqcjd.generalplatformprojectclient.model.pojo.EquipmentOrTypeBean;
import com.shqcjd.generalplatformprojectclient.model.pojo.FileBean;
import com.shqcjd.generalplatformprojectclient.model.pojo.FileManagerBean;
import com.shqcjd.generalplatformprojectclient.model.pojo.GuidanceHistoryBean;
import com.shqcjd.generalplatformprojectclient.model.pojo.GuidanceMsgBean;
import com.shqcjd.generalplatformprojectclient.model.pojo.GuideInfoBean;
import com.shqcjd.generalplatformprojectclient.model.pojo.GuideListBean;
import com.shqcjd.generalplatformprojectclient.model.pojo.InviteBean;
import com.shqcjd.generalplatformprojectclient.model.pojo.LaunchRemoteBean;
import com.shqcjd.generalplatformprojectclient.model.pojo.LoginBean;
import com.shqcjd.generalplatformprojectclient.model.pojo.RegisterBean;
import com.shqcjd.generalplatformprojectclient.model.pojo.StaffsBean;

import java.io.File;
import java.util.List;

import io.reactivex.Observable;

/**
 * api接口
 * Created by sy on 2018/12/10.
 */

public class ApiService {
    public static Observable<ResponseData<LoginBean>> login(String username, String password, long app) {
        return OkGo.<ResponseData<LoginBean>>post(HttpUrl.LOGIN)
                .params("phoneNumber",username)
                .params("password",password)
                .params("app",app)
                .converter(new JsonConvert<ResponseData<LoginBean>>(){})
                .adapt(new ObservableBody<ResponseData<LoginBean>>());

    }


    public static Observable<ResponseData<RegisterBean>> register(String phoneNumber, String password, String verification, long type) {
        return OkGo.<ResponseData<RegisterBean>>post(HttpUrl.REGISTER_USER)
                .params("phoneNumber",phoneNumber)
                .params("password",password)
                .params("verification",verification)
                .params("type",type)
                .converter(new JsonConvert<ResponseData<RegisterBean>>(){})
                .adapt(new ObservableBody<ResponseData<RegisterBean>>());

    }

    /**
     * 通过验证码登陆
     */
    public static Observable<ResponseData<LoginBean>> codeLogin(String phoneNumber, String verification, long app) {
        return OkGo.<ResponseData<LoginBean>>post(HttpUrl.CODE_LOGIN)
                .params("phoneNumber",phoneNumber)
                .params("verification",verification)
                .params("app",app)
                .converter(new JsonConvert<ResponseData<LoginBean>>(){})
                .adapt(new ObservableBody<ResponseData<LoginBean>>());

    }

    /**
     * 通过验证码登陆
     */
    public static Observable<ResponseData<String>> getVCode(String phoneNumber) {
        return OkGo.<ResponseData<String>>post(HttpUrl.GET_CODE)
                .params("phoneNumber",phoneNumber)
                .converter(new JsonConvert<ResponseData<String>>(){})
                .adapt(new ObservableBody<ResponseData<String>>());

    }

    /**
     * 添加公司
     */
    public static Observable<ResponseData<CompanyBean>> addCompany(String name) {
        return OkGo.<ResponseData<CompanyBean>>post(HttpUrl.ADD_COMPANY)
                .params("name",name)
                .converter(new JsonConvert<ResponseData<CompanyBean>>(){})
                .adapt(new ObservableBody<ResponseData<CompanyBean>>());

    }

    /**
     * 查询所有公司
     */
    public static Observable<ResponseData<List<CompanyBean>>> queryCompany() {
        return OkGo.<ResponseData<List<CompanyBean>>>get(HttpUrl.QUERY_COMPANY)
                .converter(new JsonConvert<ResponseData<List<CompanyBean>>>(){})
                .adapt(new ObservableBody<ResponseData<List<CompanyBean>>>());

    }

    /**
     * 上传文件
     */
    public static Observable<ResponseData<FileBean>> postFile(File file) {
        return OkGo.<ResponseData<FileBean>>post(HttpUrl.POST_FILE)
                .params("file", file)
                .converter(new JsonConvert<ResponseData<FileBean>>(){})
                .adapt(new ObservableBody<ResponseData<FileBean>>());

    }

    /**
     * 删除文件
     */
    public static Observable<ResponseData> deleteFile(int id) {
        return OkGo.<ResponseData>delete(HttpUrl.DELETE_FILE+id)
                .converter(new JsonConvert<ResponseData>(){})
                .adapt(new ObservableBody<ResponseData>());

    }

    /**
     * 保存草稿
     */
    public static Observable<ResponseData> saveDraft(String equipmentParam) {
        return OkGo.<ResponseData>post(HttpUrl.SAVE_DRAFT)
                .upJson(equipmentParam)
                .converter(new JsonConvert<ResponseData>(){})
                .adapt(new ObservableBody<ResponseData>());

    }

    /**
     * 点击添加设备类型，如果草稿存在，就返回草稿
     */
    public static Observable<ResponseData<DraftBean>> addsaveDraft(int tag) {
        return OkGo.<ResponseData<DraftBean>>post(HttpUrl.ADD_DRAFT)
                .params("tag", tag)
                .converter(new JsonConvert<ResponseData<DraftBean>>(){})
                .adapt(new ObservableBody<ResponseData<DraftBean>>());

    }

    /**
     * 提交设备信息
     */
    public static Observable<ResponseData<DraftBean>> commitDraft(String json) {
        return OkGo.<ResponseData<DraftBean>>post(HttpUrl.COMMIT_DRAFT)
                .upJson(json)
                .converter(new JsonConvert<ResponseData<DraftBean>>(){})
                .adapt(new ObservableBody<ResponseData<DraftBean>>());

    }

    /**
     * 删除草稿
     */
    public static Observable<ResponseData> deleteDraft(int id) {
        return OkGo.<ResponseData>delete(HttpUrl.DELETE_DRAFT+id)
                .converter(new JsonConvert<ResponseData>(){})
                .adapt(new ObservableBody<ResponseData>());

    }

    /**
     * 获取邀请列表
     */
    public static Observable<ResponseData<List<InviteBean>>> getInviteList(){
        return OkGo.<ResponseData<List<InviteBean>>>get(HttpUrl.GET_INVITE_LIST)
                .converter(new JsonConvert<ResponseData<List<InviteBean>>>(){})
                .adapt(new ObservableBody<ResponseData<List<InviteBean>>>());
    }

    /**
     * 发起远程指导
     * @param json
     * @return
     */
    public static Observable<ResponseData<LaunchRemoteBean>> launchRemote(String json){
        return OkGo.<ResponseData<LaunchRemoteBean>>post(HttpUrl.LAUNCH_REMOTE)
                .upJson(json)
                .converter(new JsonConvert<ResponseData<LaunchRemoteBean>>(){})
                .adapt(new ObservableBody<ResponseData<LaunchRemoteBean>>());
    }

    /**
     * 设备列表
     */
    public static Observable<ResponseData<List<EquipmentOrTypeBean>>> equipmentList(int tag) {
        return OkGo.<ResponseData<List<EquipmentOrTypeBean>>>get(HttpUrl.GET_DEVICE_LIST+tag)
                .converter(new JsonConvert<ResponseData<List<EquipmentOrTypeBean>>>(){})
                .adapt(new ObservableBody<ResponseData<List<EquipmentOrTypeBean>>>());

    }

    /**
     * 文件列表
     */
    public static Observable<ResponseData<List<FileManagerBean>>> fileList(int id) {
        return OkGo.<ResponseData<List<FileManagerBean>>>get(HttpUrl.GET_FILE_LIST+"/"+id+"/file_list")
                .converter(new JsonConvert<ResponseData<List<FileManagerBean>>>(){})
                .adapt(new ObservableBody<ResponseData<List<FileManagerBean>>>());

    }

    /**
     * 新增设备文件
     */
    public static Observable<ResponseData<FileManagerBean>> commitFile(String json) {
        return OkGo.<ResponseData<FileManagerBean>>post(HttpUrl.ADD_FILE)
                .upJson(json)
                .converter(new JsonConvert<ResponseData<FileManagerBean>>(){})
                .adapt(new ObservableBody<ResponseData<FileManagerBean>>());

    }

    /**
     * 删除设备文件
     */
    public static Observable<ResponseData> deleteEquipmentFile(int id) {
        return OkGo.<ResponseData>delete(HttpUrl.DELETE_EQUIPMENT_FILE+id)
                .converter(new JsonConvert<ResponseData>(){})
                .adapt(new ObservableBody<ResponseData>());
    }

    /**
     * 删除设备或设备类型
     */
    public static Observable<ResponseData>  deleteEquipmentType(int id) {
        return OkGo.<ResponseData>delete(HttpUrl.DELETE_EQUIPMENT_TYPE+id)
                .converter(new JsonConvert<ResponseData>(){})
                .adapt(new ObservableBody<ResponseData>());

    }

    /**
     * 获取员工列表
     */
    public static Observable<ResponseData<List<StaffsBean>>> staffList() {
        return OkGo.<ResponseData<List<StaffsBean>>>get(HttpUrl.STAFF_LIST)
                .converter(new JsonConvert<ResponseData<List<StaffsBean>>>(){})
                .adapt(new ObservableBody<ResponseData<List<StaffsBean>>>());

    }

    /**
     * 删除员工
     */
    public static Observable<ResponseData>  deleteStaff(int id) {
        return OkGo.<ResponseData>delete(HttpUrl.DELETE_STAFF+id)
                .converter(new JsonConvert<ResponseData>(){})
                .adapt(new ObservableBody<ResponseData>());

    }

    /**
     *  添加员工
     */
    public static Observable<ResponseData> addStaff(String json) {
        return OkGo.<ResponseData>post(HttpUrl.ADD_STAFF)
                .upJson(json)
                .converter(new JsonConvert<ResponseData>(){})
                .adapt(new ObservableBody<ResponseData>());

    }

    /**
     *  编辑员工
     */
    public static Observable<ResponseData> updateStaff(String json) {
        return OkGo.<ResponseData>put(HttpUrl.UPDATE_STAFF)
                .upJson(json)
                .converter(new JsonConvert<ResponseData>(){})
                .adapt(new ObservableBody<ResponseData>());

    }

    /**
     *  修改密码
     */
    public static Observable<ResponseData> updatePassword(String json) {
        return OkGo.<ResponseData>put(HttpUrl.UPDATE_PASSWORD)
                .upJson(json)
                .converter(new JsonConvert<ResponseData>(){})
                .adapt(new ObservableBody<ResponseData>());

    }

    /**
     *  乙方远程指导列表
     */
    public static Observable<ResponseData<GuideListBean>> guideList(int page) {
        return OkGo.<ResponseData<GuideListBean>>get(HttpUrl.Y_GUIDE_LIST+"?page="+(page-1))
                .converter(new JsonConvert<ResponseData<GuideListBean>>(){})
                .adapt(new ObservableBody<ResponseData<GuideListBean>>());

    }

    /**
     * 根据id获取设备信息信息
     */
    public static Observable<ResponseData<DraftBean>> equimentListById(int id) {
        return OkGo.<ResponseData<DraftBean>>get(HttpUrl.EQUIPMENT_INFO_BYID+id)
                .converter(new JsonConvert<ResponseData<DraftBean>>(){})
                .adapt(new ObservableBody<ResponseData<DraftBean>>());

    }

    /**
     * 获取远程指导记录列表
     */
    public static Observable<ResponseData<List<GuidanceHistoryBean>>> guideHistoryList(int id) {
        return OkGo.<ResponseData<List<GuidanceHistoryBean>>>get(HttpUrl.GUIDE_HISTORY+id)
                .converter(new JsonConvert<ResponseData<List<GuidanceHistoryBean>>>(){})
                .adapt(new ObservableBody<ResponseData<List<GuidanceHistoryBean>>>());

    }

    /**
     * 获取远程指导时间和费用信息
     */
    public static Observable<ResponseData<GuideInfoBean>> getGuideInfo(int id) {
        return OkGo.<ResponseData<GuideInfoBean>>get(HttpUrl.GET_GUIDE_INFO+id)
                .converter(new JsonConvert<ResponseData<GuideInfoBean>>(){})
                .adapt(new ObservableBody<ResponseData<GuideInfoBean>>());

    }

    /**
     * 填写备忘录
     */
    public static Observable<ResponseData> commitGuideTips(String json) {
        return OkGo.<ResponseData>post(HttpUrl.ADD_GUIDE_TIPS)
                .upJson(json)
                .converter(new JsonConvert<ResponseData>(){})
                .adapt(new ObservableBody<ResponseData>());

    }

    /**
     * 邀请处理
     * @param json
     * @return
     */
    public static Observable<ResponseData> inviteHandle(String json){
        return OkGo.<ResponseData>post(HttpUrl.INVITE_HANDLE)
                .upJson(json)
                .converter(new JsonConvert<ResponseData>(){})
                .adapt(new ObservableBody<ResponseData>());

    }

    /**
     * 获取远程指导房间内所有用户ID列表
     * @param roomId
     * @return
     */
    public static Observable<ResponseData<List<String>>> queryChannel(String roomId) {
        return OkGo.<ResponseData<List<String>>>get(HttpUrl.QUERY_CHANNEL+roomId)
                .converter(new JsonConvert<ResponseData<List<String>>>(){})
                .adapt(new ObservableBody<ResponseData<List<String>>>());

    }

    /**
     * 获取指导时的消息列表
     * @return
     */
    public static Observable<ResponseData<List<GuidanceMsgBean>>> getGuideMsgList(String guideId){
        return OkGo.<ResponseData<List<GuidanceMsgBean>>>get(HttpUrl.GET_GUIDE_MSG_LIST+guideId)
                .converter(new JsonConvert<ResponseData<List<GuidanceMsgBean>>>(){})
                .adapt(new ObservableBody<ResponseData<List<GuidanceMsgBean>>>());
    }

    /**
     * word转pdf
     */
    public static Observable<ResponseData<String>> wordToPdf(String url) {
        return OkGo.<ResponseData<String>>post(HttpUrl.WORDTOPDF)
                .params("url", url)
                .converter(new JsonConvert<ResponseData<String>>(){})
                .adapt(new ObservableBody<ResponseData<String>>());

    }

    /**
     * 使用眼镜
     * @param isUse
     * @return
     */
    public static Observable<ResponseData> useGlass(int isUse){
        return OkGo.<ResponseData>post(HttpUrl.USE_GLASS)
                .params("use_glasses",isUse)//使用眼镜0：不使用 1：使用
                .converter(new JsonConvert<ResponseData>(){})
                .adapt(new ObservableBody<ResponseData>());

    }

    /**
     * 获取使用眼镜的状态
     * @return
     */
    public static Observable<ResponseData<Integer>> useGlassState(){
        return OkGo.<ResponseData<Integer>>get(HttpUrl.USE_GLASS)
                .converter(new JsonConvert<ResponseData<Integer>>(){})
                .adapt(new ObservableBody<ResponseData<Integer>>());

    }
}
